 ///
 /// @file    taskqueue.h
 /// @author  lemon(haohb13@gmail.com)
 /// @date    2022-06-06 10:20:23
 ///
 
#ifndef __WD_TASKQUEUE_H__
#define __WD_TASKQUEUE_H__
#include "log.h"
#include <pthread.h>

#define TASKQUEUE_NOT_EXIT_FLAG 0
#define TASKQUEUE_READY_EXIT_FLAG 1

//CMD命令枚举类型
typedef enum{
    CMD_TYPE_CD=1,CMD_TYPE_LS=2,
    CMD_TYPE_PWD=3,CMD_TYPE_PUTS=4,
    CMD_TYPE_GETS=5,CMD_TYPE_RM=6,
    CMD_TYPE_MKDIR=7,CMD_TYPE_LOGIN = 8,
    CMD_TYPE_ILLEGAL=0
}CmdType;


typedef struct task_s{
	int peerfd;
	struct task_s * pnext;
    //存储命令类型
    CmdType type;
    //存储文件名
    char data[1000];

} task_t;

typedef struct taskqueue_s{
	task_t * pFront;
	task_t * pRear;
	int queSize;
	int exitFlag;//退出的标志位
	pthread_mutex_t mutex;
	pthread_cond_t cond;
} task_queue_t;
 
void queueInit(task_queue_t *);
void queueDestroy(task_queue_t*);
int queueIsEmpty(task_queue_t *);
int getTaskSize(task_queue_t *);
int taskEnqueue(task_queue_t*, int peerfd, char buffer[]);
task_t* taskDequeue(task_queue_t*);
void queueWakeup(task_queue_t*);
 
#endif
